From 396a3a4f1900b1403f45f177bb6b501e9e23c495 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 24 Feb 2006 19:16:52 +0100 Subject: [PATCH] Fix up CPU allocation and topology reporting. Signed-off-by: Keir Fraser --- xen/arch/x86/dom0_ops.c | 9 ++++++--- xen/arch/x86/setup.c | 4 ---- xen/common/dom0_ops.c | 24 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/dom0_ops.c b/xen/arch/x86/dom0_ops.c index 69fcb76aef..3ca142ad69 100644 --- a/xen/arch/x86/dom0_ops.c +++ b/xen/arch/x86/dom0_ops.c @@ -181,10 +181,13 @@ long arch_do_dom0_op(struct dom0_op *op, struct dom0_op *u_dom0_op) { dom0_physinfo_t *pi = &op->u.physinfo; - pi->threads_per_core = smp_num_siblings; - pi->cores_per_socket = boot_cpu_data.x86_max_cores; + pi->threads_per_core = + cpus_weight(cpu_sibling_map[0]); + pi->cores_per_socket = + cpus_weight(cpu_core_map[0]) / pi->threads_per_core; pi->sockets_per_node = - num_online_cpus() / (pi->threads_per_core * pi->cores_per_socket); + num_online_cpus() / cpus_weight(cpu_core_map[0]); + pi->nr_nodes = 1; pi->total_pages = total_pages; pi->free_pages = avail_domheap_pages(); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 18c8f6be51..58c143d8a1 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -437,11 +437,7 @@ void __init __start_xen(multiboot_info_t *mbi) set_in_cr4(X86_CR4_OSXMMEXCPT); if ( opt_nosmp ) - { max_cpus = 0; - smp_num_siblings = 1; - boot_cpu_data.x86_max_cores = 1; - } smp_prepare_cpus(max_cpus); diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index 340b667459..003a47b620 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -165,6 +165,7 @@ long do_dom0_op(struct dom0_op *u_dom0_op) domid_t dom; struct vcpu *v; unsigned int i, cnt[NR_CPUS] = { 0 }; + cpumask_t cpu_exclude_map; static domid_t rover = 0; dom = op->u.createdomain.domain; @@ -195,18 +196,29 @@ long do_dom0_op(struct dom0_op *u_dom0_op) read_lock(&domlist_lock); for_each_domain ( d ) for_each_vcpu ( d, v ) - cnt[v->processor]++; + if ( !test_bit(_VCPUF_down, &v->vcpu_flags) ) + cnt[v->processor]++; read_unlock(&domlist_lock); /* - * If we're on a HT system, we only use the first HT for dom0, other - * domains will all share the second HT of each CPU. Since dom0 is on - * CPU 0, we favour high numbered CPUs in the event of a tie. + * If we're on a HT system, we only auto-allocate to a non-primary HT. + * We favour high numbered CPUs in the event of a tie. */ - pro = smp_num_siblings - 1; - for ( i = pro; i < num_online_cpus(); i += smp_num_siblings ) + pro = first_cpu(cpu_sibling_map[0]); + if ( cpus_weight(cpu_sibling_map[0]) > 1 ) + pro = next_cpu(pro, cpu_sibling_map[0]); + cpu_exclude_map = cpu_sibling_map[0]; + for_each_online_cpu ( i ) + { + if ( cpu_isset(i, cpu_exclude_map) ) + continue; + if ( (i == first_cpu(cpu_sibling_map[i])) && + (cpus_weight(cpu_sibling_map[i]) > 1) ) + continue; + cpus_or(cpu_exclude_map, cpu_exclude_map, cpu_sibling_map[i]); if ( cnt[i] <= cnt[pro] ) pro = i; + } ret = -ENOMEM; if ( (d = domain_create(dom, pro)) == NULL ) -- 2.30.2